//
//  RankViewModel.swift
//  shop
//
//  Created by chen on 2025/5/13.
//

import SwiftUI

@MainActor
class RankViewModel: ObservableObject {
    
    static let shared: RankViewModel = RankViewModel()
    
    public init() {
        
    }
    
    @Published var rankList: [RankType] = [
        RankType(rankType: 1, rankName: "实时榜"),
        RankType(rankType: 2, rankName: "全天榜"),
        RankType(rankType: 3, rankName: "热推榜"),
        RankType(rankType: 7, rankName: "综合热搜榜"),
        RankType(rankType: 9, rankName: "必推榜"),
        RankType(rankType: 11, rankName: "昨日销量榜"),
        RankType(rankType: 12, rankName: "7日销量榜"),
        RankType(rankType: 13, rankName: "30日销量榜"),
        RankType(rankType: 14, rankName: "去年同期销量榜"),
        RankType(rankType: 15, rankName: "低价高佣榜")
    ]
    
    @Published var rankMap: [Int: [RankItem]] = [:]
    
    public func getRankList(rankType: Int) {
        Task{
            let queryParam:[String:Any] = [
                "version": "v1.3.1",
                "rankType": rankType,
                "pageSize": 50,
                "pageId": 1
            ]
            
            await NetManager.shared.httpGetList(.rankList, queryParam: queryParam) { (data:[RankItem]) in
                self.rankMap[rankType] = data
            }
        }
    }
}
